package mapreduce

import (
	"fmt"
	"hash/fnv"
	"strconv"
)

type jobPhase string

const (
	mapPhase	jobPhase = "Map"			//phase name
	reducePhase 		 = "Reduce"
	debugEnabled 		 = true
)

type KeyValue struct {
	Key 	string
	Value	string
}

//partition intermediate inFile for different reduce task
func reduceName(
	jobName string,		//job name
	mapTask int,		//map task no
	reduceTask int,		//reduce task no
) string {
	return "F:/tmp/mr/mrtmp." + jobName + "." + strconv.Itoa(mapTask) + "-" + strconv.Itoa(reduceTask)
}

func ihash(s string) int {
	h := fnv.New32a()
	h.Write([]byte(s))
	return int(h.Sum32() & 0x7fffffff)
}

// mergeName constructs the name of the output inFile of reduce task <reduceTask>
func mergeName(jobName string, reduceTask int) string {
	return "mrtmp." + jobName + "-res-" + strconv.Itoa(reduceTask)
}

func debug(format string, a ...interface{}) (n int, err error) {
	if debugEnabled {
		n, err = fmt.Printf(format, a)
	}
	return n, err
}